home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 2 code / Speed Development / UDemoDialogs.cp < prev    next >
Encoding:
Text File  |  1990-03-06  |  50.0 KB  |  1,700 lines  |  [TEXT/MPS ]

  1. // Copyright © 1989-1990 by Apple Computer, Inc.  All rights reserved. 
  2.  
  3.  
  4. #ifndef __UDEMODIALOGS__
  5. #include "UDemoDialogs.h"
  6. #endif
  7.  
  8. extern "C" int strncmp (const char *s1, const char *s2, int n);
  9. extern "C" char* memcpy(void*, void*, int);
  10. #define pstrcpy(p,q) memcpy(p, q, q[0]+1)                    // added for translation: Pascal strcpy
  11.  
  12. // Constants
  13. const short kNoOfLines        = 10000;
  14. const short kMaxScrollBar    = 1000;
  15. const short kTestIcon        = 1000;
  16. const short kTestAlert        = 1000;
  17. const short kTestPopup        = 235;
  18. const short kBaudPopup        = 236;
  19. const short kParityPopup    = 237;
  20. const short kTestPicture    = 1000;
  21. const short kTestStatic     = 1000;
  22. const short kMaxPlaces        = 13;
  23.  
  24. // Constants for Command Items
  25. const short cFirstItem        = 1001;
  26. const short cProcedureViews = 1001;
  27. const short cTemplateViews    = 1002;
  28. const short cMonthlyDialog    = 1003;
  29. const short cSaveDialog     = 1004;
  30. const short cMarkDialog     = 1005;
  31. const short cPageSetupDialog    = 1006;
  32. const short cHomeBrewControls    = 1007;
  33. const short cTabbingTest    = 1008;
  34. const short cCalculator     = 1009;
  35. const short cScrollingTest    = 1011;
  36. const short cFormatDialog    = 1012;
  37. const short cModelessMarkDialog    = 1013;
  38. const short cLastItem        = 1013;
  39. const short cPopupExample    = 1100;
  40.  
  41. const short mUpArrow        = 100;
  42. const short mDownArrow        = 101;
  43. const short mTemperatureChanged        = 102;
  44.  
  45.  
  46. struct FondRecord {
  47.     FamRec familyStuff;
  48.     short noOfFonts;
  49.     struct {
  50.         short size;
  51.         short style;
  52.         short resID;
  53.     } fontStuff[1000];    // not 1001!
  54. };
  55. typedef FondRecord *FondPointer, **FondHandle;
  56.  
  57. static void MakeProcedureViews(CmdNumber aCmdNumber);
  58. static void MakeTemplateViews(CmdNumber aCmdNumber, TTestApplication *aTestApp);
  59. static void MakeScrollingTest(CmdNumber aCmdNumber);
  60. static void MakeMonthlyDialog(CmdNumber aCmdNumber);
  61. static void MakeSaveDialog(CmdNumber aCmdNumber);
  62. static void MakeMarkDialog(CmdNumber aCmdNumber);
  63. static void MakeFormatDialog(CmdNumber aCmdNumber);
  64. static void MakePageSetupDialog(CmdNumber aCmdNumber);
  65. static void MakeHomeBrewControls(CmdNumber aCmdNumber);
  66. static void MakeTabTest(CmdNumber aCmdNumber);
  67. static void MakeCalculator(CmdNumber aCmdNumber);
  68. static void MakeModelessMarkDialog(CmdNumber aCmdNumber);
  69. //--------------------------------------------------------------------------------------------------
  70.  
  71. const short kMonths = 12;
  72.  
  73. long gMonthlyValues[kMonths];
  74. IDType gMonthIDs[kMonths];
  75.  
  76. //********************************************************************************************
  77. //    T T e s t A p p l i c a t i o n
  78. //********************************************************************************************
  79. //--------------------------------------------------------------------------------------------------
  80. #pragma segment AInit
  81.  
  82. pascal void 
  83. TTestApplication::ITestApplication(OSType itsMainFileType)
  84. {
  85.     Ptr                 monthIDs;
  86.     TMonthlyDialog *aMonthlyDialog;
  87.     TArrowsControl *anArrowsControl;
  88.     TTemperatureCluster *aTemperatureCluster;
  89.     TTemperatureConversionCluster *aTemperatureConversionCluster;
  90.     THomeBrewDialog *anHomeBrewDialog;
  91.     TSlider *aSlider;
  92.     TPageSetupDialog *aPageSetupDialog;
  93.     TRadioIcon *aRadioIcon;
  94.     TSumStaticText *aSumStaticText;
  95.     TCalcDialog *aCalcDialog;
  96.     TNumbersView *aNumbersView;
  97.     TFontListView *aFontListView;
  98.     TSizeListView *aSizeListView;
  99.     TModelessMarkDialog *aModelessMarkDialog;
  100.     TScrollBar *aScrollBar;
  101.     TGraph *aGraph;
  102.  
  103.     IApplication(itsMainFileType);
  104.     fLaunchWithNewDocument = FALSE;        // Suppress the creation of a new document at launch
  105.  
  106.     monthIDs = "jan feb mar apr may jun jul aug sep oct nov dec ";
  107.     BlockMove(monthIDs, (Ptr) gMonthIDs, sizeof(gMonthIDs));
  108.  
  109.     for (short i = 0 ; i < kMonths ; i++) {
  110.         gMonthlyValues[i] = (i+1) * 100;
  111.     }
  112.     if (gDeadStripSuppression) { // Hack so linker won't dead strip our custom view descendants
  113.         aMonthlyDialog = new TMonthlyDialog;
  114.         anArrowsControl = new TArrowsControl;
  115.         aTemperatureCluster = new TTemperatureCluster;
  116.         aTemperatureConversionCluster = new TTemperatureConversionCluster;
  117.         aSlider = new TSlider;
  118.         anHomeBrewDialog = new THomeBrewDialog;
  119.         aFontListView = new TFontListView;
  120.         aSizeListView = new TSizeListView;
  121.         aRadioIcon = new TRadioIcon;
  122.         aPageSetupDialog = new TPageSetupDialog;
  123.         aSumStaticText = new TSumStaticText;
  124.         aCalcDialog = new TCalcDialog;
  125.         aNumbersView = new TNumbersView;
  126.         aModelessMarkDialog = new TModelessMarkDialog;
  127.         aScrollBar = new TScrollBar;
  128.         aGraph = new TGraph;
  129.     }
  130. }    
  131.  
  132. /*--------------------------------------------------------------------------------------------------*/
  133. #pragma segment ASelCommand
  134.  
  135. pascal TCommand *
  136. TTestApplication::DoMenuCommand(CmdNumber aCmdNumber)
  137. {
  138.     TCommand *returnVal = NULL;
  139.  
  140.     switch (aCmdNumber) {
  141.         case cProcedureViews:
  142.             MakeProcedureViews(aCmdNumber);
  143.             break;
  144.         case cTemplateViews:
  145.             MakeTemplateViews(aCmdNumber, this);
  146.             break;
  147.         case cScrollingTest:
  148.             MakeScrollingTest(aCmdNumber);
  149.             break;
  150.         case cMonthlyDialog:
  151.             MakeMonthlyDialog(aCmdNumber);
  152.             break;
  153.         case cSaveDialog:
  154.             MakeSaveDialog(aCmdNumber);
  155.             break;
  156.         case cMarkDialog:
  157.             MakeMarkDialog(aCmdNumber);
  158.             break;
  159.         case cModelessMarkDialog:
  160.             MakeModelessMarkDialog(aCmdNumber);
  161.             break;
  162.         case cFormatDialog:
  163.             MakeFormatDialog(aCmdNumber);
  164.             break;
  165.         case cPageSetupDialog:
  166.             MakePageSetupDialog(aCmdNumber);
  167.             break;
  168.         case cHomeBrewControls:
  169.             MakeHomeBrewControls(aCmdNumber);
  170.             break;
  171.         case cTabbingTest:
  172.             MakeTabTest(aCmdNumber);
  173.             break;
  174.         case cCalculator:
  175.             MakeCalculator(aCmdNumber);
  176.             break;
  177.         default:
  178.             returnVal = inherited::DoMenuCommand(aCmdNumber);
  179.             break;
  180.     }
  181.     return returnVal;
  182. }
  183.  
  184.  /*--------------------------------------------------------------------------------------------------*/
  185.  
  186. static void MakeProcedureViews(CmdNumber aCmdNumber)
  187. {
  188.     RGBColor aColor;
  189.     VPoint itsLocation;
  190.     VPoint itsSize;
  191.     TextStyle ts;
  192.     TWindow *aWindow;
  193.     TDialogView *aDialogView;
  194.     TCluster *aCluster;
  195.     TRadio *aRadio[8];
  196.     TButton *aButton;
  197.     TIcon *anIcon;
  198.     TCheckBox *aCheckBox;
  199.     TPopup *aPopup;
  200.     TPicture *aPicture;
  201.     TStaticText *aStaticText;
  202.     TEditText *anEditText;
  203.     Str255 s;
  204.  
  205.     aDialogView = new TDialogView;
  206.     FailNIL(aDialogView);
  207.     SetVPt(&itsSize, 480, 900);
  208.     aDialogView->IDialogView(NULL, NULL, &gZeroVPt, &itsSize, sizeFixed,
  209.                             sizeFixed, kNoIdentifier, kNoIdentifier);
  210.     aDialogView->ParamTxt("\p^0", "\pPARAM0");
  211.     aDialogView->ParamTxt("\p^1", "\pPARAM1");
  212.  
  213.     aWindow = NewSimpleWindow(aCmdNumber, TRUE, TRUE, NULL, aDialogView);
  214.     aWindow->fFreeOnClosing = TRUE;
  215.     aWindow->fMustStagger = TRUE;
  216.     aWindow->fMustForceOnScreen = TRUE;
  217.     aWindow->SimpleStagger(kStdStaggerAmount, kStdStaggerAmount, 
  218.                           &gStdStaggerCount);
  219.  
  220.     aStaticText = new TStaticText;
  221.     FailNIL(aStaticText);
  222.     SetVPt(&itsLocation, 50, 100);
  223.     SetVPt(&itsSize, 300, 150);
  224.     aStaticText->IStaticText(aDialogView, &itsLocation, &itsSize, sizeVariable,
  225.                             sizeVariable, kTestStatic, 1);
  226.     SetRGBColor(&aColor, 0, 0, 0xFFFF);
  227.     SetTextStyle(&ts, applFont, italic, 12, &aColor);
  228.     aStaticText->InstallTextStyle(&ts, kDontRedraw);
  229.     aStaticText->SetJustification(teJustCenter, kRedraw);
  230.  
  231.     aCluster = new TCluster;
  232.     FailNIL(aCluster);
  233.     SetVPt(&itsLocation, 100, 340);
  234.     SetVPt(&itsSize, 150, 190);
  235.     aCluster->ICluster(aDialogView, &itsLocation, &itsSize, sizeVariable,
  236.                       sizeVariable, kNoResource, 0);
  237.     aCluster->SetLabel("\pA Cluster!", kRedraw);
  238.  
  239.     SetVPt(&itsSize, 130, 20);
  240.     for (short i = 0 ; i <= 7 ; i++) {
  241.         aRadio[i] = new TRadio;
  242.         FailNIL(aRadio[i]);
  243.         SetVPt(&itsLocation, 10, (i + 1) * 20);
  244.         aRadio[i]->IRadio(aCluster, &itsLocation, &itsSize, sizeVariable, sizeVariable, (StringPtr) "\p", i == 0);
  245.         SetTextStyle(&ts, systemFont, Style((1 << i)/2), 12, &gRGBBlack);
  246.         aRadio[i]->InstallTextStyle(&ts, kDontRedraw);
  247.         switch (i) {
  248.             case 0:
  249.                 aRadio[i]->SetText("\pPlain", kRedraw);
  250.                 break;
  251.             case 1:
  252.                 aRadio[i]->SetText("\pBold", kRedraw);
  253.                 break;
  254.             case 2:
  255.                 aRadio[i]->SetText("\pItalic", kRedraw);
  256.                 break;
  257.             case 3:
  258.                 aRadio[i]->SetText("\pUnderline", kRedraw);
  259.                 break;
  260.             case 4:
  261.                 aRadio[i]->SetText("\pOutline", kRedraw);
  262.                 break;
  263.             case 5:
  264.                 aRadio[i]->SetText("\pShadow", kRedraw);
  265.                 break;
  266.             case 6:
  267.                 aRadio[i]->SetText("\pCondense", kRedraw);
  268.                 break;
  269.             case 7:
  270.                 aRadio[i]->SetText("\pExtend", kRedraw);
  271.                 break;
  272.         }
  273.     }
  274.  
  275.     aCheckBox = new TCheckBox;
  276.     FailNIL(aCheckBox);
  277.     SetVPt(&itsLocation, 100, 540);
  278.     SetVPt(&itsSize, 100, 20);
  279.     aCheckBox->ICheckBox(aDialogView, &itsLocation, &itsSize, sizeFixed, sizeFixed,
  280.                         "\pCheck Box", FALSE);
  281.     SetTextStyle(&ts, applFont, NULL, 12, &gRGBBlack);
  282.     aCheckBox->InstallTextStyle(&ts, kRedraw);
  283.     
  284.     aButton = new TButton;
  285.     FailNIL(aButton);
  286.     SetVPt(&itsLocation, 270, 540);
  287.     SetVPt(&itsSize, 100, 28);
  288.     aButton->IButton(aDialogView, &itsLocation, &itsSize, sizeVariable, sizeVariable,
  289.                     "\pPush Button");
  290.     SetTextStyle(&ts, applFont, NULL, 10, &gRGBBlack);
  291.     aButton->InstallTextStyle(&ts, kDontRedraw);
  292.     aButton->fAdornment = adnRRect;
  293.     SetPt(&aButton->fPenSize, 3, 3);
  294.     aButton->Inset(4, 4, kRedraw);
  295.     
  296.     anIcon = new TIcon;
  297.     FailNIL(anIcon);
  298.     SetVPt(&itsLocation, 130, 570);
  299.     SetVPt(&itsSize, 35, 35);
  300.     anIcon->IIcon(aDialogView, &itsLocation, &itsSize, sizeFixed, sizeFixed,
  301.                  kTestIcon, kPreferColor);
  302.     anIcon->fAdornment = kFrame | adnShadow;
  303.     anIcon->ViewEnable(TRUE, kDontRedraw);
  304.     anIcon->Inset(1, 1, kDontRedraw);
  305.  
  306.     if (gConfiguration.hasHierarchicalMenus) {
  307.         aPopup = new TPopup;
  308.         FailNIL(aPopup);
  309.         SetVPt(&itsLocation, 290, 589);
  310.         SetVPt(&itsSize, 120, 22);
  311.         aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
  312.                       sizeVariable, kTestPopup, 2, 50);
  313.  
  314.         aPopup = new TPopup;
  315.         FailNIL(aPopup);
  316.         SetVPt(&itsLocation, 290, 624);
  317.         SetVPt(&itsSize, 120, 22);
  318.         aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
  319.                       sizeVariable, kBaudPopup, 1, 50);
  320.  
  321.         aPopup = new TPopup;
  322.         FailNIL(aPopup);
  323.         SetVPt(&itsLocation, 290, 659);
  324.         SetVPt(&itsSize, 120, 22);
  325.         aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
  326.                       sizeVariable, kParityPopup, 1, 50);
  327.     }
  328.  
  329.     aPicture = new TPicture;
  330.     FailNIL(aPicture);
  331.     SetVPt(&itsLocation, 100, 660);
  332.     SetVPt(&itsSize, 0x18C - 0xF0 + 16, 0x12C - 0x8F + 16);
  333.     aPicture->IPicture(aDialogView, &itsLocation, &itsSize, sizeVariable,
  334.                       sizeVariable, kTestPicture);
  335.     SetPt(&aPicture->fPenSize, 2, 2);
  336.     aPicture->fAdornment = adnRRect | adnShadow;
  337.     aPicture->ViewEnable(TRUE, kDontRedraw);
  338.     aPicture->Inset(8, 8, kDontRedraw);
  339.     
  340.     aStaticText = new TStaticText;
  341.     FailNIL(aStaticText);
  342.     SetVPt(&itsLocation, 20, 620);
  343.     SetVPt(&itsSize, 100, 20);
  344.     aStaticText->IStaticText(aDialogView, &itsLocation, &itsSize, sizeVariable,
  345.                             sizeVariable, kTestStatic, 2);
  346.     SetRGBColor(&aColor, 0xFFFF, 0, 0);
  347.     aStaticText->InstallColor(&aColor, kRedraw);
  348.     
  349.     anEditText = new TEditText;
  350.     FailNIL(anEditText);
  351.     SetVPt(&itsLocation, 140, 620);
  352.     SetVPt(&itsSize, 100, 22);
  353.     anEditText->IEditText(aDialogView, &itsLocation, &itsSize, 255);
  354.     SetTextStyle(&ts, applFont, 0, 12, &gRGBBlack);
  355.     anEditText->InstallTextStyle(&ts, kDontRedraw);
  356.     anEditText->SetJustification(teJustRight, kDontRedraw);
  357.     anEditText->SetText("\pEditText", kRedraw);
  358.     
  359. //    aDialogView->DoSelectEditText(anEditText, TRUE);
  360.     aWindow->Open();
  361. }
  362.  
  363.  /*--------------------------------------------------------------------------------------------------*/
  364.  
  365. static void MakeTemplateViews(CmdNumber aCmdNumber, TTestApplication *aTestApp)
  366. {
  367.     TWindow *aWindow;
  368.     TDialogView *aDialogView;
  369.     TPopup *aPopup;
  370.  
  371.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  372.     FailNIL(aWindow);
  373.     aDialogView = (TDialogView *) aWindow->FindSubView('DLOG');
  374.     if (gConfiguration.hasHierarchicalMenus)
  375.         aPopup = (TPopup *) (aTestApp->DoCreateViews(NULL, aDialogView, cPopupExample,
  376.                                       &gZeroVPt));
  377.     aDialogView->ParamTxt("\p^0", "\pPARAM0");
  378.     aDialogView->ParamTxt("\p^1", "\pPARAM1");
  379.     aWindow->Open();
  380. }
  381.  /*--------------------------------------------------------------------------------------------------*/
  382.  
  383. static void MakeScrollingTest(CmdNumber aCmdNumber)
  384. {
  385.     TWindow *aWindow;
  386.     Point minSize;
  387.  
  388.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  389.     FailNIL(aWindow);
  390.     SetPt(&minSize, 315, 260);
  391.     aWindow->SetResizeLimits(minSize, *((Point *) &aWindow->fResizeLimits.bottom));
  392.     aWindow->Open();
  393. }
  394.  
  395.  /*--------------------------------------------------------------------------------------------------*/
  396.  
  397. static void MakeMonthlyDialog(CmdNumber aCmdNumber)
  398. {
  399.     TWindow *aWindow;
  400.     TMonthlyDialog *aMonthlyDialog;
  401.  
  402.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  403.     FailNIL(aWindow);
  404.     aMonthlyDialog = (TMonthlyDialog *) aWindow->FindSubView('DLOG');
  405.     if (aMonthlyDialog != NULL)
  406.         aMonthlyDialog->StuffValues();
  407.     aWindow->Open();
  408. }
  409.  /*--------------------------------------------------------------------------------------------------*/
  410.  
  411. static void MakeSaveDialog(CmdNumber aCmdNumber)
  412. {
  413.     TWindow *aWindow;
  414.     IDType dismisser;
  415.  
  416.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  417.     FailNIL(aWindow);
  418.     dismisser = ((TDialogView *) aWindow->FindSubView('DLOG'))->PoseModally();
  419.  
  420.     #if qDebug
  421.         if (dismisser == 'yes ')
  422.             printf("The user said yes.\n");
  423.         else if (dismisser == 'no  ')
  424.             printf("The user said no.\n");
  425.         else if (dismisser == 'cncl')
  426.             printf("The user cancelled the dialog.\n");
  427.         else
  428.         printf("I don't know how the user responded.\n");
  429.     #endif qDebug
  430.     aWindow->Close();
  431. }
  432.  
  433.  /*--------------------------------------------------------------------------------------------------*/
  434.  
  435. static void MakeMarkDialog(CmdNumber aCmdNumber)
  436. {
  437.     TWindow *aWindow;
  438.     IDType dismisser;
  439.     Str255 theMark;
  440.  
  441.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  442.     FailNIL(aWindow);
  443.  
  444.     dismisser = ((TDialogView *) aWindow->FindSubView('DLOG'))->PoseModally();
  445.     #if qDebug
  446.         if (dismisser == 'ok  ') {
  447.             ((TEditText *) aWindow->FindSubView('mark'))->GetText((StringPtr) &theMark);
  448.             if (theMark[0] == 0)
  449.                 printf("No mark specified.\n");
  450.             else
  451.                 printf("The mark is ‘%P’.\n", &theMark);
  452.         } else
  453.             printf("The dialog was cancelled.\n");
  454.     #endif
  455.     aWindow->Close();
  456. }
  457.  
  458. /*--------------------------------------------------------------------------------------------------*/
  459.  
  460. static void MakeModelessMarkDialog(CmdNumber aCmdNumber)
  461. {
  462.     TWindow *aWindow;
  463.  
  464.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  465.     FailNIL(aWindow);
  466.     aWindow->Open();
  467. }
  468.  
  469. static void MakeFormatDialog(CmdNumber aCmdNumber)
  470. {
  471.     TWindow *aWindow;
  472.     TDialogView *theDialog;
  473.     IDType dismisser;
  474.     TSizeListView *theSizeListView;
  475.     TFontListView *theFontListView;
  476.  
  477.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  478.     FailNIL(aWindow);
  479.     theDialog = (TDialogView *) aWindow->FindSubView('DLOG');
  480.  
  481.     theSizeListView = (TSizeListView *) theDialog->FindSubView('slst');
  482.     theSizeListView->InitSizeList();
  483.  
  484.     theFontListView = (TFontListView *) theDialog->FindSubView('flst');
  485.     theFontListView->InitFontList();
  486.  
  487.     dismisser = theDialog->PoseModally();
  488.     #if qDebug
  489.         if( dismisser != 'ok  ')
  490.             printf("The dialog was cancelled.\n");
  491.     #endif
  492.     aWindow->Close();
  493. }
  494.  
  495.  
  496.  /*--------------------------------------------------------------------------------------------------*/
  497.  
  498. static void MakePageSetupDialog(CmdNumber aCmdNumber)
  499. {
  500.     TWindow *aWindow;
  501.     TPageSetupDialog *theDialog;
  502.     IDType dismisser;
  503.     VHSelect orientation;
  504.  
  505.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  506.     FailNIL(aWindow);
  507.     theDialog = (TPageSetupDialog *) aWindow->FindSubView('DLOG');
  508.     theDialog->GetOrientation(&orientation);
  509.     ((TRadioIcon *) theDialog->FindSubView('vert'))->HiliteState(orientation == v, kDontRedraw);
  510.     ((TRadioIcon *) theDialog->FindSubView('horz'))->HiliteState(orientation == h, kDontRedraw);
  511.  
  512.     dismisser = theDialog->PoseModally();
  513.     #if qDebug
  514.         if (dismisser == 'ok  ') {
  515.         } else
  516.             printf("The dialog was cancelled.\n");
  517.     #endif
  518.     aWindow->Close();
  519. }
  520.  
  521.  /*--------------------------------------------------------------------------------------------------*/
  522.  
  523. static void MakeHomeBrewControls(CmdNumber aCmdNumber)
  524. {
  525.     TWindow *aWindow;
  526.  
  527.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  528.     FailNIL(aWindow);
  529.     aWindow->Open();
  530. }
  531.  
  532.  /*--------------------------------------------------------------------------------------------------*/
  533.  
  534. static void MakeTabTest(CmdNumber aCmdNumber)
  535. {
  536.     TWindow *aWindow;
  537.  
  538.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  539.     FailNIL(aWindow);
  540.     aWindow->Open();
  541. }
  542.  
  543.  /*--------------------------------------------------------------------------------------------------*/
  544.  
  545. static void MakeCalculator(CmdNumber aCmdNumber)
  546. {
  547.     TWindow *aWindow;
  548.     TCalcDialog *aCalcDialog;
  549.  
  550.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  551.     FailNIL(aWindow);
  552.     aCalcDialog = (TCalcDialog *) aWindow->FindSubView('DLOG');
  553.     aCalcDialog->ClearSum();
  554.     aWindow->Open();
  555. }
  556.  
  557. /*--------------------------------------------------------------------------------------------------*/
  558. #pragma segment ARes
  559.  
  560. pascal void TTestApplication::DoSetupMenus()
  561. {
  562.     inherited::DoSetupMenus();
  563.     
  564.     for (short i = cFirstItem; i<=cLastItem; i++)
  565.         Enable(i, TRUE);    
  566. }
  567.  
  568.  /*--------------------------------------------------------------------------------------------------*/
  569. #pragma segment AFields
  570.  
  571. pascal void 
  572. TTestApplication::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  573.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  574. {
  575.     (*DoToField)("\pTTestApplication", NULL, bClass, DoToField_StaticLink);
  576.     TApplication::Fields(DoToField, DoToField_StaticLink);
  577. }
  578.  
  579. //********************************************************************************************
  580. //    T N u m b e r s V i e w 
  581. //*******************************************************************************************
  582. //--------------------------------------------------------------------------------------------------
  583. #pragma segment ARes
  584.  
  585. pascal void TNumbersView::Draw(Rect *area)
  586. {
  587.     VRect viewRect;
  588.     long i, firstLine, lastLine;
  589.     VPoint vPt;
  590.     Point pt;
  591.     Str255 s;
  592.  
  593.     QDToViewRect(area, &viewRect);
  594.     viewRect.right = viewRect.right - 1;
  595.     viewRect.bottom = viewRect.bottom - 1;
  596.     firstLine = (viewRect.top / 16) + 1;
  597.     lastLine = (viewRect.bottom / 16) + 1;
  598.     SetPortTextStyle(&gSystemStyle);
  599.     for (i = firstLine; i<=lastLine; i++) {
  600.         SetVPt(&vPt, 0, i * 16);
  601.         pt = ViewToQDPt(&vPt);
  602.         MoveTo(pt.h, pt.v);
  603.         NumToString(i, s);
  604.         DrawString(s);
  605.     }
  606.  
  607.     inherited::Draw(area);
  608. }
  609.  
  610.  /*--------------------------------------------------------------------------------------------------*/
  611. #pragma segment AFields
  612.  
  613. pascal void 
  614. TNumbersView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  615.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  616. {
  617.     (*DoToField)("\pTNumbersView", NULL, bClass, DoToField_StaticLink);
  618.     TView::Fields(DoToField, DoToField_StaticLink);
  619. }
  620.  
  621. //********************************************************************************************
  622. //    T M o n t h l y D i a l o g 
  623. //*******************************************************************************************
  624. //--------------------------------------------------------------------------------------------------
  625. #pragma segment AClose
  626.  
  627. pascal void 
  628. TMonthlyDialog::DismissDialog(IDType dismisser)
  629. {
  630.     for (short i = 0; i < kMonths; i++)
  631.         gMonthlyValues[i] = ((TNumberText *) FindSubView(gMonthIDs[i]))->GetValue();
  632.  
  633.     inherited::DismissDialog(dismisser);
  634. }
  635.  
  636. /*--------------------------------------------------------------------------------------------------*/
  637. #pragma segment ARes
  638.  
  639. pascal TCommand *
  640. TMonthlyDialog::DoKeyCommand(short ch, short aKeyCode, EventInfo *info)
  641. {
  642.     /* If option-tab is pressed, deselect the current edit text and 
  643.        leave nothing selected. This is for test purposes only.    
  644.        It is not part of the Macintosh user interface. */
  645.  
  646.     if ((ch == chTab) && (info->theOptionKey)) {
  647.         DoSelectEditText(NULL, FALSE);
  648.         return (NULL);
  649.     } else
  650.         return (inherited::DoKeyCommand(ch, aKeyCode, info));
  651. }
  652.  
  653. /*--------------------------------------------------------------------------------------------------*/
  654. #pragma segment ARes
  655.  
  656. pascal Boolean
  657. TMonthlyDialog::DeselectCurrentEditText(void)
  658. {
  659.     TGraph        *aGraph;
  660.     TNumberText *theNumberText;
  661.     
  662.     aGraph = (TGraph *) FindSubView('graf');
  663.     for (short which = 0; which < kMonths; which++) {
  664.         if (fCurrentEditText->fIdentifier == gMonthIDs[which]) {
  665.             theNumberText = (TNumberText *) FindSubView(gMonthIDs[which]);
  666.             if (theNumberText)
  667.                 aGraph->SetPoint(which+1, theNumberText->GetValue());
  668.             aGraph->ComputeBars(kRedraw);
  669.             break;
  670.         }
  671.     }
  672.  
  673.     return inherited::DeselectCurrentEditText();
  674. }
  675.  
  676. /*--------------------------------------------------------------------------------------------------*/
  677. #pragma segment ARes
  678.  
  679. pascal void
  680. TMonthlyDialog::StuffValues()
  681. {
  682.     TGraph *aGraph;
  683.     TNumberText *aNumberText;
  684.     
  685.     aGraph = (TGraph *) FindSubView('graf');
  686.     for (short i = 0; i < kMonths; i++) {
  687.         aNumberText = (TNumberText *) FindSubView(gMonthIDs[i]);
  688.         if (aNumberText)
  689.             aNumberText->SetValue(gMonthlyValues[i], kDontRedraw);
  690.         aGraph->SetPoint(i+1, gMonthlyValues[i]);
  691.     }
  692.     aGraph->ComputeBars(kDontRedraw);
  693. }
  694.  
  695.  /*--------------------------------------------------------------------------------------------------*/
  696. #pragma segment AFields
  697.  
  698. pascal void 
  699. TMonthlyDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  700.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  701. {
  702.     (*DoToField)("\pTMonthlyDialog", NULL, bClass, DoToField_StaticLink);
  703.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  704. }
  705.  
  706. //**************************************************************************************************
  707. //  T M o d e l e s s M a r k D i a l o g                                                           
  708. //**************************************************************************************************
  709. //--------------------------------------------------------------------------------------------------
  710. #pragma segment ARes
  711.  
  712. pascal void 
  713. TModelessMarkDialog::DoChoice (TView *origView, short itsChoice)
  714. {
  715.     Str255    theMark;
  716.  
  717.     switch (itsChoice) {
  718.         case mDefaultKey:            // This handles when user presses the 'return' key
  719.         case mCancelKey:            // This handles when user presses the 'esc' key
  720.         case mButtonHit:            // This handles clicking in 'OK' or 'Cancel' buttons
  721.             if (origView->fIdentifier == fDefaultItem) {
  722.                 ((TEditText *) FindSubView('mark'))->GetText((StringPtr) &theMark);
  723.                 ((TWindow *)GetWindow())->Close();
  724.                 #if qDebug
  725.                 printf("The mark is ‘%P’\n", &theMark);
  726.                 #endif
  727.             } else if (origView->fIdentifier == fCancelItem)
  728.                 ((TWindow *)GetWindow())->Close();
  729.             break;
  730.     }
  731. }
  732.  
  733.  /*--------------------------------------------------------------------------------------------------*/
  734. #pragma segment AFields
  735.  
  736. pascal void 
  737. TModelessMarkDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  738.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  739. {
  740.     (*DoToField)("\pTModelessMarkDialog", NULL, bClass, DoToField_StaticLink);
  741.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  742. }
  743.  
  744. //********************************************************************************************
  745. //    T F o n t L i s t V i e w
  746. //********************************************************************************************
  747. //--------------------------------------------------------------------------------------------------
  748. #pragma segment AOpen
  749.  
  750. short FondAfter(StringPtr fontName, short noOfFonds)
  751. // Find the FOND whose name follows fontName alphabetically, and return its id and name
  752. {
  753.     Handle theFondResource;
  754.     short lastID = 0;
  755.     short thisID;
  756.     ResType itsType;
  757.     Boolean foundFOND = FALSE;
  758.     Str255 lastName;
  759.     Str255 thisName;
  760.  
  761.     pstrcpy((char *) lastName, "\p~~~~~~~~");
  762.     for (short index = 1; index < noOfFonds; index++) {
  763.         theFondResource = GetIndResource('FOND', index);
  764.         GetResInfo(theFondResource, &thisID, &itsType, thisName);
  765.         if ((CompareStrings((StringPtr) &thisName, fontName) == 1) && (CompareStrings((StringPtr) &thisName, (StringPtr) &lastName) == -1)) {
  766.             lastID = thisID;
  767.             pstrcpy(lastName, thisName);
  768.             foundFOND = TRUE;
  769.         }
  770.     }
  771.     if (foundFOND)
  772.         pstrcpy(fontName, lastName);
  773.     else                                             // Skip duplicate FOND names
  774.         pstrcpy(fontName, "\p");
  775.     
  776.     return lastID;
  777. }
  778.  
  779. //--------------------------------------------------------------------------------------------------
  780. #pragma segment AOpen
  781.  
  782. pascal void
  783. TFontListView::InitFontList()
  784. {
  785.     FontListPtr    pFondIDs;
  786.     short        noOfFonds;
  787.     Str255        aString;
  788.     short        fondID;
  789.  
  790.     fFontList = (FontListPtr) NULL;
  791.     noOfFonds = CountResources('FOND');
  792.     if (noOfFonds > kMaxFonds)
  793.         noOfFonds = kMaxFonds;
  794.     pFondIDs = (FontListPtr) NewPermPtr(noOfFonds * sizeof(short));    // array of shorts
  795.     FailNIL(pFondIDs);
  796.     
  797.     pstrcpy(aString, "\p ");
  798.     for (short i = 0; i <= noOfFonds; i++) {                // put each FOND's id in the list… 
  799.         fondID = FondAfter(aString, noOfFonds);            // …in alphabetical order
  800.         (*pFondIDs)[i] = fondID;
  801.         if (Length(aString) == 0) {                        // finished early
  802.             noOfFonds = i;
  803.             break;                                        // break from a for loop
  804.         }
  805.     }
  806.     
  807.     fFontList = pFondIDs;
  808.     InsRowLast(noOfFonds, 16);
  809.  
  810.     SelectItem(1, kDontExtend, kHighlight, kSelect);
  811. }
  812.  
  813. //--------------------------------------------------------------------------------------------------
  814. #pragma segment AClose
  815.  
  816. pascal void
  817. TFontListView::Free()
  818. {
  819.     DisposeIfPtr(fFontList);
  820.     fFontList = (FontListPtr) NULL;
  821.     
  822.     inherited::Free();
  823. }
  824.  
  825. //--------------------------------------------------------------------------------------------------
  826. #pragma segment ARes
  827.  
  828. pascal void
  829. TFontListView::GetItemText(short anItem, StringPtr aString)
  830. {
  831.     Handle theFondResource;
  832.     short itsID;
  833.     ResType itsType;
  834.  
  835.     itsID = (*fFontList)[anItem-1];
  836.     theFondResource = GetResource('FOND', itsID);
  837.     GetResInfo(theFondResource, &itsID, &itsType, aString);
  838. }
  839.  
  840. /*--------------------------------------------------------------------------------------------------*/
  841. #pragma segment ARes
  842.  
  843. pascal void
  844. TFontListView::SelectItem(short anItem, Boolean extendSelection, Boolean highlight,
  845.                             Boolean select)
  846. {
  847.     TView *aView;
  848.  
  849.     inherited::SelectItem(anItem, extendSelection, highlight, select);
  850.  
  851.     if (select) {
  852.         aView = ((TView *) GetWindow())->FindSubView('slst');
  853.         FailNIL(aView);
  854.         ((TSizeListView *) aView)->InstallFontFamily((*fFontList)[anItem-1]);
  855.     }
  856. }
  857.  
  858.  /*--------------------------------------------------------------------------------------------------*/
  859. #pragma segment AFields
  860.  
  861. pascal void 
  862. TFontListView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  863.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  864. {
  865.     (*DoToField)("\pTFontListView", NULL, bClass, DoToField_StaticLink);
  866.       (*DoToField)("\pfFontList", (Ptr) &fFontList, bPointer, DoToField_StaticLink);
  867.     TTextListView::Fields(DoToField, DoToField_StaticLink);
  868. }
  869.  
  870. //********************************************************************************************
  871. //    T S i z e L i s t V i e w
  872. //********************************************************************************************
  873. /*--------------------------------------------------------------------------------------------------*/
  874. #pragma segment ARes
  875.  
  876. pascal void TSizeListView::InitSizeList()
  877. {
  878.     fSelection = 0;
  879.     fSelectedSize = 9;
  880.     fFondIndex = 0;
  881. }
  882.  
  883. //--------------------------------------------------------------------------------------------------
  884. #pragma segment ARes
  885.  
  886. pascal void
  887. TSizeListView::GetItemText(short anItem, StringPtr aString)
  888. {
  889.     short noOfSizes;
  890.     FondHandle theFond;
  891.  
  892.     theFond = (FondHandle) GetResource('FOND', fFondIndex);
  893.     noOfSizes = 0;
  894.     for (short i = 0; i <= theFond[0]->noOfFonts; i++) {
  895.         if (theFond[0]->fontStuff[i].style == 0 )
  896.             noOfSizes = noOfSizes + 1;
  897.         if (noOfSizes == anItem ) {
  898.             NumToString(theFond[0]->fontStuff[i].size, aString);
  899.             return;
  900.         }
  901.     }
  902.     pstrcpy(aString, "\p");                                        // set it to the empty string
  903. }
  904.  
  905. /*--------------------------------------------------------------------------------------------------*/
  906. #pragma segment AOpen
  907.  
  908. pascal void
  909. TSizeListView::InstallFontFamily(short theFondIndex)
  910. {
  911.     FondHandle theFond;
  912.     short noOfSizes;
  913.     short sizeToSelect;
  914.  
  915.     theFond = (FondHandle) GetResource('FOND', theFondIndex);
  916.     noOfSizes = 0;
  917.     sizeToSelect = 0;
  918.     for (short i = 0; i <= theFond[0]->noOfFonts; i++)
  919.         if (theFond[0]->fontStuff[i].style == 0) {
  920.             noOfSizes = noOfSizes + 1;
  921.             if (theFond[0]->fontStuff[i].size == fSelectedSize)
  922.                 sizeToSelect = noOfSizes;
  923.         }
  924.     fFondIndex = theFondIndex;
  925.     SetNumberOfItems(noOfSizes);
  926.     SelectItem(sizeToSelect, kDontExtend, kDontHighlight, kSelect);
  927.     ForceRedraw();
  928. }
  929.  
  930. /*--------------------------------------------------------------------------------------------------*/
  931. #pragma segment ARes
  932.  
  933. pascal void
  934. TSizeListView::SelectItem(short anItem, Boolean extendSelection, Boolean highlight,
  935.                             Boolean select)
  936. {
  937.     Str255 aString;
  938.     TNumberText *theSizeView;
  939.     long fontSize;
  940.  
  941.     inherited::SelectItem(anItem, extendSelection, highlight, select);
  942.  
  943.     if ( select && (anItem != 0) ) {
  944.         GetItemText(anItem, aString);
  945.         theSizeView = (TNumberText *) (((TView *) GetWindow())->FindSubView('size'));
  946.         theSizeView->SetText((StringPtr) &aString, kRedraw);
  947.         theSizeView->SetSelection(0, SHRT_MAX, kRedraw);
  948.         StringToNum(aString, &fontSize);
  949.         fSelectedSize = (short) fontSize;
  950.     }
  951. }
  952.  
  953. /*--------------------------------------------------------------------------------------------------*/
  954. #pragma segment ARes
  955.  
  956. pascal void
  957. TSizeListView::SetNumberOfItems(short aNumber)
  958. {
  959.     SelectItem(0, kDontExtend, kHighlight, kSelect);
  960.  
  961.     if ( fNumOfRows > aNumber )
  962.         DelItemFirst(fNumOfRows - aNumber);
  963.     else if ( fNumOfRows < aNumber )
  964.         InsItemFirst(aNumber - fNumOfRows);
  965. }
  966.  
  967.  /*--------------------------------------------------------------------------------------------------*/
  968. #pragma segment AFields
  969.  
  970. pascal void 
  971. TSizeListView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  972.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  973. {
  974.     (*DoToField)("\pTSizeListView", NULL, bClass, DoToField_StaticLink);
  975.       (*DoToField)("\pfSelection", (Ptr) &fSelection, bInteger, DoToField_StaticLink);
  976.       (*DoToField)("\pfSelectedSize", (Ptr) &fSelectedSize, bInteger, DoToField_StaticLink);
  977.     (*DoToField)("\pfFondIndex", (Ptr) &fFondIndex, bInteger, DoToField_StaticLink);
  978.     TTextListView::Fields(DoToField, DoToField_StaticLink);
  979. }
  980.  
  981. //********************************************************************************************
  982. //    T P a g e S e t u p D i a l o g
  983. //********************************************************************************************
  984. //--------------------------------------------------------------------------------------------------
  985. #pragma segment AOpen
  986.  
  987. TPageSetupDialog::TPageSetupDialog()
  988. {
  989.     fOrientation = v;
  990. }
  991.  
  992. //--------------------------------------------------------------------------------------------------
  993. #pragma segment ARes
  994.  
  995. pascal void
  996. TPageSetupDialog::DoChoice(TView *origView, short itsChoice)
  997. {
  998.     
  999.     VHSelect newOrientation;
  1000.     TCheckBox *tallAdjCheckBox;
  1001.  
  1002.     switch (itsChoice) {
  1003.         case mIconHit:
  1004.             if (origView->fIdentifier == 'vert')
  1005.                 newOrientation = v;
  1006.             else
  1007.                 newOrientation = h;
  1008.             if (newOrientation != fOrientation) {
  1009.                 ((TRadioIcon *) FindSubView('vert'))->HiliteState(newOrientation == v, kRedraw);
  1010.                 ((TRadioIcon *) FindSubView('horz'))->HiliteState(newOrientation == h, kRedraw);
  1011.                 tallAdjCheckBox = (TCheckBox *) FindSubView('tall');
  1012.                 tallAdjCheckBox->DimState(newOrientation == h, kRedraw);
  1013.                 tallAdjCheckBox->SetVal(0, kRedraw);
  1014.                 fOrientation = newOrientation;
  1015.             }
  1016.             break;
  1017.             
  1018.         default:
  1019.             inherited::DoChoice(origView, itsChoice);
  1020.     }
  1021. }
  1022.  
  1023. /*--------------------------------------------------------------------------------------------------*/
  1024. #pragma segment ARes
  1025.  
  1026. pascal void
  1027. TPageSetupDialog::GetOrientation(VHSelect *theOrientation)
  1028. {
  1029.     *theOrientation = fOrientation;
  1030. }
  1031.  
  1032. /*--------------------------------------------------------------------------------------------------*/
  1033. #pragma segment AFields
  1034.  
  1035. pascal void 
  1036. TPageSetupDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1037.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1038. {
  1039.     (*DoToField)("\pTPageSetupDialog", NULL, bClass, DoToField_StaticLink);
  1040.       (*DoToField)("\pfOrientation", (Ptr) &fOrientation, bVHSelect, DoToField_StaticLink);
  1041.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  1042. }
  1043.  
  1044. //********************************************************************************************
  1045. //    T R a d i o I c o n
  1046. //********************************************************************************************
  1047. //--------------------------------------------------------------------------------------------------
  1048. #pragma segment ADoCommand
  1049.  
  1050. pascal void
  1051. TRadioIcon::TrackMouse(TrackPhase aTrackPhase, VPoint *, 
  1052.                         VPoint *, VPoint *,
  1053.                         Boolean )
  1054. {
  1055.     if (aTrackPhase == trackPress)
  1056.         DoChoice(this, mIconHit);
  1057. }
  1058.  
  1059.  /*--------------------------------------------------------------------------------------------------*/
  1060. #pragma segment AFields
  1061.  
  1062. pascal void 
  1063. TRadioIcon::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1064.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1065. {
  1066.     (*DoToField)("\pTRadioIcon", NULL, bClass, DoToField_StaticLink);
  1067.     TIcon::Fields(DoToField, DoToField_StaticLink);
  1068. }
  1069.  
  1070. //********************************************************************************************
  1071. //    T H o m e B r e w D i a l o g
  1072. //********************************************************************************************
  1073. /*--------------------------------------------------------------------------------------------------*/
  1074. #pragma segment ARes
  1075.  
  1076. pascal Boolean
  1077. THomeBrewDialog::DoSetCursor(Point , RgnHandle )
  1078. // localPoint & cursorRgn removed from declaration so CFront won't complain that it isn't used
  1079. {    
  1080.     CursHandle theCursor;
  1081.  
  1082.     theCursor = GetCursor(crossCursor);
  1083.     SetCursor(*theCursor);
  1084.     return TRUE;
  1085. }
  1086.  
  1087. /*--------------------------------------------------------------------------------------------------*/
  1088. #pragma segment ARes
  1089.  
  1090. pascal TView *
  1091. THomeBrewDialog::HandleCursor(VPoint *theMouse, RgnHandle cursorRgn)
  1092. {
  1093.     if (Focus() && DoSetCursor(ViewToQDPt(theMouse), cursorRgn))
  1094.         return this;
  1095.     else
  1096.         return (TView *) NULL;
  1097. }
  1098.  
  1099.  /*--------------------------------------------------------------------------------------------------*/
  1100. #pragma segment AFields
  1101.  
  1102. pascal void 
  1103. THomeBrewDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1104.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1105. {
  1106.     (*DoToField)("\pTHomeBrewDialog", NULL, bClass, DoToField_StaticLink);
  1107.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  1108. }
  1109.  
  1110. //********************************************************************************************
  1111. //    T A r r o w s C o n t r o l
  1112. //********************************************************************************************
  1113. //--------------------------------------------------------------------------------------------------
  1114. #pragma segment AOpen
  1115.  
  1116. pascal void
  1117. TArrowsControl::IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams)
  1118. {
  1119.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  1120.     fLastChange = 0;
  1121. }
  1122.  
  1123. /*--------------------------------------------------------------------------------------------------*/
  1124. #pragma segment AClose
  1125.  
  1126. pascal void
  1127. TArrowsControl::TrackMouse(TrackPhase aTrackPhase, VPoint *, 
  1128.                           VPoint *, VPoint *nextPoint, 
  1129.                           Boolean )
  1130. // anchorPoint, previousPoint, & mouseDidMove removed from declaration so CFront won't
  1131. // complain that they aren't used
  1132. {
  1133.     if (TickCount() >= fLastChange + 5) {
  1134.         fLastChange = TickCount();
  1135.         if (aTrackPhase == trackPress)
  1136.             fLastChange = fLastChange + 10;
  1137.  
  1138.         if (ContainsMouse(nextPoint))
  1139.             if (nextPoint->v <= fSize.v / 2)
  1140.                 DoChoice(this, mUpArrow);
  1141.             else
  1142.                 DoChoice(this, mDownArrow);
  1143.     }
  1144. }
  1145.  
  1146.  /*--------------------------------------------------------------------------------------------------*/
  1147. #pragma segment AFields
  1148.  
  1149. pascal void 
  1150. TArrowsControl::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1151.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1152. {
  1153.     (*DoToField)("\pTArrowsControl", NULL, bClass, DoToField_StaticLink);
  1154.     (*DoToField)("\pfLastChange", (Ptr) &fLastChange, bLongInt, DoToField_StaticLink);
  1155.     TPicture::Fields(DoToField, DoToField_StaticLink);
  1156. }
  1157.  
  1158. //******************************************************************************************
  1159. //  TTemperatureCluster
  1160. //******************************************************************************************
  1161. //--------------------------------------------------------------------------------------------------
  1162. #pragma segment ARes
  1163.  
  1164. pascal void
  1165. TTemperatureCluster::DoChoice(TView *, short itsChoice)
  1166. // origView removed from declaration so CFront won't complain that it isn't used
  1167. {
  1168.     TNumberText *theNumberText;
  1169.     long theNumber;
  1170.  
  1171.     switch (itsChoice) {
  1172.         case mUpArrow:
  1173.         case mDownArrow:
  1174.             theNumberText = (TNumberText *) FindSubView('Numb');
  1175.             theNumber = theNumberText->GetValue();
  1176.             if (itsChoice == mUpArrow)
  1177.                 theNumber++;
  1178.             else
  1179.                 theNumber--;
  1180.             theNumberText->SetValue(theNumber, kRedraw);
  1181.             // fall thru
  1182.         default:
  1183.             inherited::DoChoice(this,mTemperatureChanged);
  1184.             break;
  1185.     }
  1186. }
  1187.  
  1188. //--------------------------------------------------------------------------------------------------
  1189.  
  1190. #pragma segment ARes
  1191.  
  1192. pascal long
  1193. TTemperatureCluster::GetValue()
  1194. {
  1195.     TNumberText *numberText;
  1196.  
  1197.     numberText = (TNumberText *) FindSubView('Numb');
  1198.     return numberText->GetValue();
  1199. }
  1200.  
  1201. //--------------------------------------------------------------------------------------------------
  1202. #pragma segment ARes
  1203.  
  1204. pascal void
  1205. TTemperatureCluster::SetValue(long newValue, Boolean redraw)
  1206. {
  1207.     TNumberText *numberText;
  1208.  
  1209.     numberText = (TNumberText *) FindSubView('Numb');
  1210.     numberText->SetValue(newValue,redraw);
  1211. }
  1212.  
  1213.  /*--------------------------------------------------------------------------------------------------*/
  1214. #pragma segment AFields
  1215.  
  1216. pascal void 
  1217. TTemperatureCluster::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1218.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1219. {
  1220.     (*DoToField)("\pTTemperatureCluster", NULL, bClass, DoToField_StaticLink);
  1221.     TCluster::Fields(DoToField, DoToField_StaticLink);
  1222. }
  1223.  
  1224. //******************************************************************************************
  1225. //  TTemperatureConversionCluster
  1226. //******************************************************************************************
  1227. //--------------------------------------------------------------------------------------------------
  1228. #pragma segment ARes
  1229.  
  1230. pascal void
  1231. TTemperatureConversionCluster::DoChoice(TView *origView, short itsChoice)
  1232. {
  1233.     TTemperatureCluster *Celsius;
  1234.     TTemperatureCluster *Fahrenheit;
  1235.  
  1236.     if (itsChoice == mTemperatureChanged) {
  1237.         Celsius = (TTemperatureCluster *) FindSubView('Cels');
  1238.         FailNIL(Celsius);
  1239.         Fahrenheit = (TTemperatureCluster *) FindSubView('Fahr');
  1240.         FailNIL(Fahrenheit);
  1241.         if (origView == Celsius)
  1242.             Fahrenheit->SetValue(Celsius->GetValue()*1.8+32,kRedraw);
  1243.         else {
  1244.             if (origView == Fahrenheit)
  1245.                 Celsius->SetValue((Fahrenheit->GetValue()-32)/1.8,kRedraw);
  1246.         }
  1247.     }
  1248.     else
  1249.         inherited::DoChoice(this,mTemperatureChanged);
  1250. }
  1251.  
  1252.  /*--------------------------------------------------------------------------------------------------*/
  1253. #pragma segment AFields
  1254.  
  1255. pascal void 
  1256. TTemperatureConversionCluster::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1257.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1258. {
  1259.     (*DoToField)("\pTTemperatureConversionCluster", NULL, bClass, DoToField_StaticLink);
  1260.     TCluster::Fields(DoToField, DoToField_StaticLink);
  1261. }
  1262.  
  1263. //********************************************************************************************
  1264. //    T S l i d e r
  1265. //********************************************************************************************
  1266. //--------------------------------------------------------------------------------------------------
  1267. #pragma segment AOpen
  1268.  
  1269. pascal void 
  1270. TSlider::IRes(TDocument *, TView *itsSuperView, Ptr *itsParams)
  1271. // itsDocument removed from declaration so CFront won't complain that it isn't used
  1272. {
  1273.     PicHandle knobPicture;
  1274.     Rect knobRect;
  1275.     Rect *tmpR;
  1276.  
  1277.     inherited::IRes(NULL, itsSuperView, itsParams);
  1278.     knobPicture = GetPicture(1002);
  1279.     fKnobPicture = knobPicture;
  1280.     
  1281.     tmpR = &knobPicture[0]->picFrame;
  1282.     SetPt(((Point *) &knobRect.top), (short) fSize.h - (tmpR->right - tmpR->left), (short) fSize.v - 16);
  1283.     knobRect.right = knobRect.left + tmpR->right - tmpR->left;
  1284.     knobRect.bottom = knobRect.top + tmpR->bottom - tmpR->top;
  1285.  
  1286.     fMaxTop = knobRect.top;
  1287.     fMinTop = knobRect.top - 84;
  1288.     fKnobRect = knobRect;
  1289.     fValue = 0;
  1290. }
  1291.  
  1292. /*--------------------------------------------------------------------------------------------------*/
  1293. #pragma segment ARes
  1294.  
  1295. pascal Boolean
  1296. TSlider::ContainsMouse(VPoint *theMouse)
  1297. {
  1298.     Rect knobRect;
  1299.  
  1300.     GetKnobRect(&knobRect);
  1301.     return PtInRect(VPtToPt(theMouse), &knobRect);
  1302. }
  1303.  
  1304. /*--------------------------------------------------------------------------------------------------*/
  1305. #pragma segment ARes
  1306.  
  1307. pascal void
  1308. TSlider::Draw(Rect *area)
  1309.  
  1310. {
  1311.     inherited::Draw(area);                                /* This draws everything but the knob */
  1312.     DrawKnob();
  1313. }
  1314.  
  1315. /*--------------------------------------------------------------------------------------------------*/
  1316. #pragma segment ARes
  1317.  
  1318. pascal void
  1319. TSlider::DrawKnob()
  1320. {
  1321.     Rect knobRect;
  1322.  
  1323.     GetKnobRect(&knobRect);
  1324.     LoadResource(Handle(fKnobPicture));                 /* In case it was purged from memory */
  1325.     DrawPicture(fKnobPicture, &knobRect);
  1326. }
  1327.  
  1328. /*--------------------------------------------------------------------------------------------------*/
  1329. #pragma segment ARes
  1330.  
  1331. pascal void
  1332. TSlider::GetKnobRect(Rect *knobRect)
  1333. {
  1334.     *knobRect = fKnobRect;
  1335.     OffsetRect(knobRect, 0, -(fValue * 12));
  1336. }
  1337.  
  1338. /*--------------------------------------------------------------------------------------------------*/
  1339. #pragma segment ARes
  1340.  
  1341. pascal void
  1342. TSlider::TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *previousPoint,
  1343.                     VPoint *nextPoint, Boolean )
  1344. // mouseDidMove removed from declaration so CFront won't complain that it isn't used
  1345. {
  1346.     Rect oldRect;
  1347.     Rect newRect;
  1348.     Rect difference;
  1349.     RgnHandle savedClip;
  1350.     short base;
  1351.     short offset;
  1352.  
  1353.     GetKnobRect(&oldRect);
  1354.     newRect = oldRect;
  1355.  
  1356.     /* Compute rectangle of knob's current position */
  1357.     offset = (short) Min(Max(previousPoint->v - anchorPoint->v, fMinTop - newRect.top), 
  1358.                  fMaxTop - newRect.top);
  1359.     OffsetRect(&oldRect, 0, offset);
  1360.  
  1361.     /* Compute rectangle of knob's new position */
  1362.     offset = (short) Min(Max(nextPoint->v - anchorPoint->v, fMinTop - newRect.top), 
  1363.                  fMaxTop - newRect.top);
  1364.     OffsetRect(&newRect, 0, offset);
  1365.  
  1366.     /* If the mouse was release, pin the knob to a value and set slider's value */
  1367.     if (aTrackPhase == trackRelease) {
  1368.         base = (short) fSize.v - 16 - newRect.top;
  1369.         offset = base - ((base + 6) / 12 * 12);
  1370.         OffsetRect(&newRect, 0, offset);
  1371.         fValue = (short) ((fSize.v - 16 - newRect.top) / 12);
  1372.     }
  1373.  
  1374.     /* To redraw minimal amount, compute difference between old and new positions */
  1375.     difference = oldRect;
  1376.     if (oldRect.top > newRect.top)
  1377.         difference.top = (short) Max(oldRect.top, newRect.bottom);
  1378.     else
  1379.         difference.bottom = (short) Min(oldRect.bottom, newRect.top);
  1380.  
  1381.     savedClip = NewRgn();
  1382.     FailNIL(savedClip);
  1383.     GetClip(savedClip);
  1384.  
  1385.     ClipRect(&difference);
  1386.     inherited::Draw(&difference);
  1387.  
  1388.     SetClip(savedClip);
  1389.     DisposeRgn(savedClip);
  1390.     DrawPicture(fKnobPicture, &newRect);
  1391. }
  1392.  
  1393.  /*--------------------------------------------------------------------------------------------------*/
  1394. #pragma segment AFields
  1395.  
  1396. pascal void 
  1397. TSlider::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1398.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1399. {
  1400.     (*DoToField)("\pTSlider", NULL, bClass, DoToField_StaticLink);
  1401.     (*DoToField)("\pfValue", (Ptr) &fValue, bInteger, DoToField_StaticLink);
  1402.     (*DoToField)("\pfKnobPicture", (Ptr) &fKnobPicture, bHandle, DoToField_StaticLink);
  1403.     (*DoToField)("\pfKnobRect", (Ptr) &fKnobRect, bRect, DoToField_StaticLink);
  1404.     (*DoToField)("\pfMinTop", (Ptr) &fMinTop, bInteger, DoToField_StaticLink);
  1405.     (*DoToField)("\pfMaxTop", (Ptr) &fMaxTop, bInteger, DoToField_StaticLink);
  1406.     TPicture::Fields(DoToField, DoToField_StaticLink);
  1407. }
  1408.  
  1409. //********************************************************************************************
  1410. //    T S u m S t a t i c T e x t
  1411. //********************************************************************************************
  1412. #pragma segment ARes
  1413.  
  1414. pascal void
  1415. TSumStaticText::Draw(Rect *area)
  1416. {
  1417.     Rect theRect;
  1418.  
  1419.     /* Make sure the gray background gets completely erased */
  1420.     GetQDExtent(&theRect);
  1421.     InsetRect(&theRect, fPenSize.h, fPenSize.v);
  1422.     EraseRect(&theRect);
  1423.     inherited::Draw(area);
  1424. }
  1425.  
  1426.  /*--------------------------------------------------------------------------------------------------*/
  1427. #pragma segment AFields
  1428.  
  1429. pascal void 
  1430. TSumStaticText::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1431.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1432. {
  1433.     (*DoToField)("\pTSumStaticText", NULL, bClass, DoToField_StaticLink);
  1434.     TStaticText::Fields(DoToField, DoToField_StaticLink);
  1435. }
  1436.  
  1437. //********************************************************************************************
  1438. //    T C a l c D i a l o g
  1439. //********************************************************************************************
  1440. //--------------------------------------------------------------------------------------------------
  1441. #pragma segment ARes
  1442.  
  1443. pascal void
  1444. TCalcDialog::DoChoice(TView *origView, short itsChoice)
  1445. {
  1446.     IDType origID;
  1447.  
  1448.     origID = origView->fIdentifier;
  1449.     switch (itsChoice) {
  1450.         case mOKHit:                                         /*??? Should be mControlHit*/
  1451.             switch (origID & 0xFF) {
  1452.                 case 'C':
  1453.                     ClearSum();
  1454.                     break;
  1455.                 case '=':
  1456.                 case 'E':
  1457.                     TotalSum(noOperator);
  1458.                     break;
  1459.                 case '/':
  1460.                     TotalSum(divOperator);
  1461.                     break;
  1462.                 case '*':
  1463.                     TotalSum(mulOperator);
  1464.                     break;
  1465.                 case '-':
  1466.                     TotalSum(subOperator);
  1467.                     break;
  1468.                 case '+':
  1469.                     TotalSum(addOperator);
  1470.                     break;
  1471.                 default:
  1472.                     NewDigit((short) origID & 0xFF);
  1473.                     break;
  1474.             }
  1475.             break;
  1476.             
  1477.         default:
  1478.             inherited::DoChoice(origView, itsChoice);
  1479.             break;
  1480.     }
  1481. }
  1482.  
  1483. /*--------------------------------------------------------------------------------------------------*/
  1484. #pragma segment ARes
  1485.  
  1486. pascal TCommand *
  1487. TCalcDialog::DoKeyCommand(short ch, short aKeyCode, EventInfo *)
  1488. // info removed from declaration so CFront won't complain that it isn't used
  1489. {
  1490.     Boolean foundIt;
  1491.     long whoCares;
  1492.     IDType theID;
  1493.     TView *theView;
  1494.  
  1495.     foundIt = TRUE;
  1496.     if (aKeyCode == 0x47)                             /* Clear key */
  1497.         theID = 'keyC';
  1498.     else if ((ch == chEnter) || (ch == chReturn))
  1499.         theID = 'keyE';
  1500.     else
  1501.         switch (ch) {
  1502.             case '0':
  1503.             case '1':
  1504.             case '2':
  1505.             case '3':
  1506.             case '4':
  1507.             case '5':
  1508.             case '6':
  1509.             case '7':
  1510.             case '8':
  1511.             case '9':
  1512.             case '.':
  1513.             case '+':
  1514.             case '-':
  1515.             case '*':
  1516.             case '/':
  1517.             case '=':
  1518.                 theID = 'key ' | ch;
  1519.                 break;
  1520.             default:
  1521.                 foundIt = FALSE;
  1522.                 SysBeep(1);
  1523.                 break;
  1524.         }
  1525.         
  1526.     if (foundIt) {
  1527.         theView = FindSubView(theID);
  1528.         if (theView->Focus()) {
  1529.             ((TControl *) theView)->Hilite();
  1530.             Delay(5, &whoCares);
  1531.             ((TControl *) theView)->Hilite();
  1532.         }
  1533.         DoChoice(theView, mOKHit);                        /*??? mButtonHit? */
  1534.     }
  1535.     return NULL;
  1536. }
  1537.  
  1538. /*--------------------------------------------------------------------------------------------------*/
  1539. #pragma segment ARes
  1540.  
  1541. pascal void TCalcDialog::ClearSum()
  1542. {
  1543.     fArgument = 0.0;
  1544.     fSum = 0.0;
  1545.     fOperator = noOperator;
  1546.     fDecimalPoint = FALSE;
  1547.     fRestart = TRUE;
  1548.     ((TStaticText *) FindSubView('SUMM'))->SetText("\p0", kRedraw);
  1549. }
  1550.  
  1551. /*--------------------------------------------------------------------------------------------------*/
  1552. #pragma segment ARes
  1553.  
  1554. pascal void TCalcDialog::FetchValue(long double *aValue)
  1555. {
  1556.     Str255 theStr;
  1557.  
  1558.     ((TStaticText *) FindSubView('SUMM'))->GetText((StringPtr) theStr);
  1559.     p2cstr((StringPtr) theStr);
  1560.     sscanf((char *) theStr, "%Lf", aValue);
  1561. }
  1562.  
  1563. /*--------------------------------------------------------------------------------------------------*/
  1564.  
  1565. static pascal short POS(StringPtr subStr, StringPtr theStr)
  1566. {
  1567.     short lSub = Length(subStr);
  1568.     short lStr = Length(theStr);
  1569.     char * p;
  1570.     
  1571.     if (theStr == NULL || subStr == NULL || (lSub > lStr)) return 0;
  1572.     
  1573.     p = (char *) &theStr[1];
  1574.     for (short index = 1; index <= 1 + (lStr - lSub); index++)
  1575.     {
  1576.         if (strncmp((char *) &subStr[1], p++, lSub))
  1577.             return index;
  1578.     }
  1579.     return 0;
  1580. }
  1581.  
  1582. static pascal void Truncate(StringPtr theStr)
  1583. {
  1584.     char theChar;
  1585.  
  1586.     if (Length(theStr) > 1) {
  1587.         theChar = theStr[Length(theStr)];
  1588.         if ( (theChar == '0') || (theChar == '.') )
  1589.             theStr[0] -= 1;
  1590.         if ( theChar == '0' )
  1591.             Truncate(theStr);
  1592.     }
  1593. }
  1594.  
  1595. pascal void TCalcDialog::SetValue()
  1596. {
  1597.     short thePos = 0;
  1598.     Str255 theStr;
  1599.     long double aExtended;
  1600.     int *decpt = NULL;
  1601.     int *sign = NULL;
  1602.  
  1603.     aExtended = fSum;
  1604.     sprintf((char *) theStr, "%Lf", aExtended);
  1605.     c2pstr((char *) theStr);
  1606.     thePos = POS("\p.", theStr);
  1607.     if (thePos != 0)
  1608.         Truncate(theStr);
  1609.     if ((thePos > kMaxPlaces) || 
  1610.             ((thePos != 0) && (POS("\p000000", theStr) == thePos + 1))) {
  1611.         aExtended = fSum;
  1612.         sprintf((char *) theStr, "%.2g", aExtended);
  1613.         c2pstr((char *) theStr);
  1614.     }
  1615.     if (Length(theStr) > kMaxPlaces)
  1616.         theStr[0] = kMaxPlaces;
  1617.     
  1618.     ((TStaticText *) FindSubView('SUMM'))->SetText((StringPtr) &theStr, kRedraw);
  1619. }
  1620.  
  1621. /*--------------------------------------------------------------------------------------------------*/
  1622. #pragma segment ARes
  1623.  
  1624. pascal void 
  1625. TCalcDialog::TotalSum(CalcOperator newOperator)
  1626. {
  1627.     long double aValue;
  1628.     
  1629.     FetchValue(&aValue);
  1630.     fArgument = aValue;
  1631.     switch (fOperator) {
  1632.         case noOperator:
  1633.             fSum = fArgument;
  1634.             break;
  1635.         case divOperator:
  1636.             fSum = fSum / fArgument;
  1637.             break;
  1638.         case mulOperator:
  1639.             fSum = fSum * fArgument;
  1640.             break;
  1641.         case subOperator:
  1642.             fSum = fSum - fArgument;
  1643.             break;
  1644.         case addOperator:
  1645.             fSum = fSum + fArgument;
  1646.             break;
  1647.     }
  1648.     SetValue();
  1649.     fRestart = TRUE;
  1650.     fArgument = fSum;
  1651.     fOperator = newOperator;
  1652. }
  1653.  
  1654. /*--------------------------------------------------------------------------------------------------*/
  1655. #pragma segment ARes
  1656.  
  1657. static void SetIt(TStaticText *theText, StringPtr theStr, short theNumber)
  1658. {
  1659.     theStr[Length(theStr) + 1] = theNumber;
  1660.     theStr[0] += 1;
  1661.     theText->SetText(theStr, kRedraw);
  1662. }
  1663.  
  1664. pascal void 
  1665. TCalcDialog::NewDigit(short theNumber)
  1666. {
  1667.     TStaticText *theText;
  1668.     Str255 theStr;
  1669.  
  1670.     theText = (TStaticText *) FindSubView('SUMM');
  1671.     if (fRestart)
  1672.         pstrcpy(theStr, "\p");
  1673.     else
  1674.         theText->GetText((StringPtr) &theStr);
  1675.         
  1676.     if (Length(theStr) < kMaxPlaces) {
  1677.         fRestart = FALSE;
  1678.         if ((theNumber == '.') && !fDecimalPoint)
  1679.             fDecimalPoint = TRUE;
  1680.         SetIt(theText, theStr, theNumber);
  1681.     }
  1682. }
  1683.  
  1684.  
  1685.  /*--------------------------------------------------------------------------------------------------*/
  1686. #pragma segment AFields
  1687.  
  1688. pascal void 
  1689. TCalcDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1690.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1691. {
  1692.     (*DoToField)("\pTCalcDialog", NULL, bClass, DoToField_StaticLink);
  1693.       (*DoToField)("\pfSum", (Ptr) &fSum, bExtended, DoToField_StaticLink);
  1694.       (*DoToField)("\pfArgument", (Ptr) &fArgument, bExtended, DoToField_StaticLink);
  1695.     (*DoToField)("\pfOperator", (Ptr) &fOperator, bInteger, DoToField_StaticLink);
  1696.     (*DoToField)("\pfDecimalPoint", (Ptr) &fDecimalPoint, bBoolean, DoToField_StaticLink);
  1697.     (*DoToField)("\pfRestart", (Ptr) &fRestart, bBoolean, DoToField_StaticLink);
  1698.     TPicture::Fields(DoToField, DoToField_StaticLink);
  1699. }
  1700.